using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using StudentManagement.Application.Services;
using System.Threading.Tasks;

namespace StudentManagement.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class DashboardController : ControllerBase
    {
        private readonly IStudentService _studentService;
        private readonly IClassService _classService;
        private readonly ICourseService _courseService;

        public DashboardController(
            IStudentService studentService,
            IClassService classService,
            ICourseService courseService)
        {
            _studentService = studentService;
            _classService = classService;
            _courseService = courseService;
        }

        /// <summary>
        /// 获取仪表盘统计数据
        /// </summary>
        [HttpGet("stats")]
        [Authorize]
        public async Task<IActionResult> GetDashboardStats()
        {
            try
            {
                // 获取学生总数
                var studentCount = await _studentService.GetStudentCountAsync();
                
                // 获取班级总数
                var classCount = await _classService.GetClassCountAsync();
                
                // 获取课程总数
                var courseCount = await _courseService.GetCourseCountAsync();
                
                // 模拟今日考勤率（实际应用中应该从数据库获取）
                var attendanceRate = 95.5;
                
                return Ok(new
                {
                    studentCount,
                    classCount,
                    courseCount,
                    attendanceRate
                });
            }
            catch (System.Exception ex)
            {
                return StatusCode(500, new { message = "获取仪表盘数据失败", error = ex.Message });
            }
        }
    }
}